package com.srit.system.bean;

import java.util.Calendar;

import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 时效
 * 
 * @author guan
 * 
 */
public class EffectTime {
	protected static Logger logger = LoggerFactory.getLogger(EffectTime.class);

	private Integer id;
	private Integer groupId;
	private Integer section;// 分段
	private Integer startHour;// 开始时间
	private Integer interval;// 间隔
	private Integer minutes;// 分钟

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getGroupId() {
		return groupId;
	}

	public void setGroupId(Integer groupId) {
		this.groupId = groupId;
	}

	public Integer getSection() {
		return section;
	}

	public void setSection(Integer section) {
		this.section = section;
	}

	public Integer getStartHour() {
		return startHour;
	}

	public void setStartHour(Integer startHour) {
		this.startHour = startHour;
	}

	public Integer getMinutes() {
		return minutes;
	}

	public void setMinutes(Integer minutes) {
		this.minutes = minutes;
	}

	public Integer getInterval() {
		return interval;
	}

	public void setInterval(Integer interval) {
		this.interval = interval;
	}

	private int nowSection;// 当前段

	public int getNowSection() {
		Calendar now = Calendar.getInstance();
		int nowHours = now.get(Calendar.HOUR_OF_DAY);
		// int nowHours=7;
		return (nowHours - this.startHour) / this.interval;
	}

	public String[] getShowArray() {
		String[] result = null;
		if (!this.validateRule()) {
			logger.debug("验证不通过");
		} else {
			logger.debug("验证通过");
			result = new String[this.getSection()];
			int j = 0;
			for (int i = this.getNowSection(); i < this.getSection()
					+ this.getNowSection(); i++) {
				int from = this.getStartHour() + i * this.getInterval();
				result[j] = ("[" + (from + this.getInterval()) + ","
						+ (from + 2 * this.getInterval()) + "]");
				j++;
			}
		}
		return result;
	}

	/**
	 * 校验规则
	 * 
	 * @return
	 */
	public boolean validateRule() {
		if (this.startHour + this.section * this.interval >= 24) {
			return true;
		} else {
			return false;
		}
	}

	public static void main(String[] args) {
		EffectTime et = new EffectTime();
		et.setSection(5);
		et.setInterval(6);
		et.setStartHour(8);
		// 每天8点钟开始，隔着6小时报4段
		System.out.println(ArrayUtils.toString(et.getShowArray()));
	}
}
